class ImageFetcher {
  constructor(token) {
    this.token = token; // 用于请求的授权令牌
  }

  async fetchImage(imageUrl) {
    let image = '';
    
    if (imageUrl) {
      try {
        const response = await fetch(`/api${imageUrl}`, {
          headers: {
            Authorization: this.token, // 添加请求头
          },
        });

        if (response.ok) {
          const blob = await response.blob();
          image = URL.createObjectURL(blob);
        } else {
          console.error('Failed to load image:', response.statusText);
        }
      } catch (error) {
        console.error('Error fetching image:', error);
      }
    }

    return image; // 返回获取到的图片
  }
}

// 导出 ImageFetcher 类
export default ImageFetcher;
